var CashDailyReport = {
    id: "CashDailyReportTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

CashDailyReport.resetSearch = function () {
    CashDailyReport.naturalDaySearch();
    dynamicForm();
};
//全院现金日报
CashDailyReport.cashDaily1 = function () {
    document.getElementById("cashDailySelection").value = "hospital";
};
//科室现金日报
CashDailyReport.cashDaily2 = function () {
    document.getElementById("cashDailySelection").value = "departmental";
    dynamicForm();
};
CashDailyReport.naturalDaySearch = function () {
    document.getElementById("settleAccounts").value="0";
    var date1 = new Date();
    var currentYear1 = date1.getFullYear();       // 当前年份
    var currentMonth1 = date1.getMonth() + 1;    // 当前月份
    var currentDay1 = date1.getDate();         // 今日日期 几号
    if (currentMonth1 < 10) currentMonth1 = "0" + currentMonth1;
    if (currentDay1 < 10) currentDay1 = "0" + currentDay1;
    $("#startTime").val(currentYear1 + "-" + currentMonth1 + "-" + currentDay1 + " " + "00:00:00");
    $("#endTime").val(currentYear1 + "-" + currentMonth1 + "-" + currentDay1 + " " + "23:59:59");
    $(".timeBox > div button").eq(0).addClass('actionClick').siblings().removeClass('actionClick');
    dynamicForm();
};

CashDailyReport.settleAccounts = function () {
    document.getElementById("settleAccounts").value="1";
    var AccountsTime = $("#sttleAccountsTime").val();
    var date1 = new Date();
    var currentYear1 = date1.getFullYear();       // 当前年份
    var currentMonth1 = date1.getMonth() + 1;    // 当前月份
    var currentDay1 = date1.getDate();         // 今日日期 几号
    if (currentMonth1 < 10) currentMonth1 = "0" + currentMonth1;
    if (currentDay1 < 10) currentDay1 = "0" + currentDay1;
    var date2 = new Date();
    date2.setDate(date2.getDate() - 1);
    var currentYears2 = date2.getFullYear();       // 当前年份
    var currentMonths2 = date2.getMonth() + 1;    // 当前月份
    var currentDays2 = date2.getDate();         // 今日日期 几号
    if (currentMonths2 < 10) currentMonths2 = "0" + currentMonths2;
    if (currentDays2 < 10) currentDays2 = "0" + currentDays2;
    $("#startTime").val(currentYears2 + "-" + currentMonths2 + "-" + currentDays2 + " " + AccountsTime);
    $("#endTime").val(currentYear1 + "-" + currentMonth1 + "-" + currentDay1 + " " + AccountsTime)
    $(".timeBox > div button").eq(1).addClass('actionClick').siblings().removeClass('actionClick');
    dynamicForm();
};

function dynamicForm() {
    var startTime = $('#startTime').val();
    var equation = $('#equation').val();
    var endTime = $('#endTime').val();
    var settleAccounts = $('#settleAccounts').val();
    var obj = $("#cashDailySelection").val();
    var abbreviation= $("#abbreviation", parent.document).val();
    $.ajax({
        type: "post",
        url: Feng.ctxPath + "/cashDailyReport/getList",
        dataType: "json",
        data: {
            'startTime': startTime,
            'endTime': endTime,
            'settleAccounts': settleAccounts,
            'obj':obj,
            'equation':equation,
            'abbreviation':abbreviation
        },
        success: function (data) {
            var arr = [];
            arr.push({radio: true});
            arr.push({"title": '日期', "field": 'rechargeTime', switchable: true, sortable: true, align: 'center', width: 120});
            arr.push({"title": '日总收入', "field": 'totalDailyIncome', switchable: true, sortable: true, align: 'center', width: 110});
            if (data[0] == null || data[0] == undefined || data[0] == "") {
                console.log('返回数据为空');
            } else {
                for (var i = 0; i < (Object.keys(data[0])).length; i++) {
                    var property = (Object.keys(data[0]))[i];
                    if (property != 'rechargeTime' && property != 'totalDailyIncome' && property != 'selectItem') {
                        arr.push({
                            "title": property,
                            "field": property,
                            switchable: true,
                            sortable: true,
                            align: 'center',
                            width: 110
                        });
                    }
                }
            }
            $('#CashDailyReportTable').bootstrapTable('destroy').bootstrapTable({
                data: data,
                toolbar: '#toolbar',
                cache: false,
                striped: true,
                sidePagination: "client",
                sortOrder: "desc",
                pageSize: 500,
                pageNumber: 1,
                pageList: [500, 1000],
                showToggle: true,
                showColumns: true,
                showExport: true,
                exportDataType: "basic",
                pagination: true,
                strictSearch: true,
                search: true,
                columns: arr,
                height: $(window).height() - 76
            });
        }
    })
}

$(function () {
    CashDailyReport.naturalDaySearch();
    $(document).on('click', '#laydate_clear,#laydate_today,#laydate_ok,#aa', function () {
        dynamicForm();
    });
    checkDate = function () {
        dynamicForm();
    };
});